const express = require("express");
const router = express.Router();
const adminsDao = require("../dao/mysql/AdminsDao");
const usersDao = require("../dao/mysql/UsersDao");

//html后缀，表示请求的页面
router.get("/logout.do", (req, res) => {
    res.json({
        code: 200,
        msg: "注销成功",
    });
});

router.post("/modifyPassword.do", (req, res, next) => {
    if (req.body) {
        let type = req.body.type;
        let obj = {};
        obj.id = req.body.id;
        if (type == "0") {
            obj.apassword = req.body.newPassword;
            adminsDao.update(obj).then((data) => {
                res.json({
                    code: 200,
                    msg: "修改成功",
                });
            });
        } else if (type == "1") {
            obj.upassword = req.body.newPassword;
            usersDao.update(obj).then((data) => {
                res.json({
                    code: 200,
                    msg: "修改成功",
                });
            });
        } else if (type == "2") {
            obj.upassword = req.body.newPassword;
            usersDao.update(obj).then((data) => {
                res.json({
                    code: 200,
                    msg: "修改成功",
                });
            });
        }
    }
});

module.exports = router;